﻿// See https://aka.ms/new-console-template for more information
using RulesEngine.Extensions;
using RulesEngine.Models;
using System.Dynamic;

Console.WriteLine("Hello, World!");



 
List<Workflow> workflows = new List<Workflow>();
Workflow workflow = new Workflow();
workflow.WorkflowName = "工作流迁移规则";

List<Rule> rules = new List<Rule>();

Rule rule = new Rule();
rule.RuleName = "报销金额<3";
 
rule.ErrorMessage = "Over expected.";
rule.Expression = "count < 3";
rule.RuleExpressionType = RuleExpressionType.LambdaExpression;

Rule rule2 = new Rule();
rule2.RuleName = "报销金额>=3";
 
rule2.Expression = "count >=3";
rule2.RuleExpressionType = RuleExpressionType.LambdaExpression;
rule2.ErrorMessage = "报销金额大于等于3才走这条路";

 

rules.Add(rule);
rules.Add(rule2);


workflow.Rules = rules;

workflows.Add(workflow);

var bre = new RulesEngine.RulesEngine(workflows.ToArray(), null);

dynamic datas = new ExpandoObject();
datas.count = 1;
var inputs = new dynamic[]
  {
                    datas
  };

List<RuleResultTree> resultList = bre.ExecuteAllRulesAsync("工作流迁移规则", inputs).Result;

bool outcome = false;

//Different ways to show test results:
outcome = resultList.TrueForAll(r => r.IsSuccess);

resultList.OnSuccess((eventName) => {
    Console.WriteLine($"Result '{eventName}' is as expected.");
    outcome = true;
});

resultList.OnFail(() => {
    outcome = false;
});

Console.WriteLine($"Test outcome: {outcome}.");